mui.init();
var showobject = document.getElementById("show");
/*
 * phone手机号,guideId所在群导购ID,targetId目标ID,db创建websql
 * */
var phone = readData(localStorage.phone);
var guideId = readData(localStorage.guideId);
var targetId;
var db = openDatabase('messageChat', '1.0', 'messageChatOfHistory DB', 4 * 1024 * 1024);
var demo = new Vue({
	el: '#main',
	data: {
		accountMes: []
	},
	methods: {
		openPage: openPage,
		init: init
	},
	ready: function() {

	}
});
window.addEventListener('add',function(){
      init()
});

init();
function init() {
	var accountUrl = getUrl("47getAccount");
	var accountHeader = getHeader();
	var accountid = readData(localStorage.accountnum);
	demo.$http({
		url: accountUrl,
		method: 'POST',
		headers: accountHeader,
		data: "id=" + accountid,
		timeout: 10000
	}).then(function(respons) {
		if (respons.data.code == "0") {
			console.log(JSON.stringify(respons.data.obj))
			var accounts = respons.data.obj.account;
			targetId = respons.data.obj.account.id;
			if (accounts["headImg"] == 'null' || !accounts["headImg"]) {
				accounts["headImg"] = '../../image/my/pl_tp.png';
			}
			//this.$set('accountMes', accounts);
			demo.accountMes = accounts;
		}
	}, function() {
		console.log('获取成员信息失败...')
	});
}

function openPage() {
	if (readData(localStorage.account) == readData(localStorage.accountnum)) {
		mui.openWindow({
			url: 'selfTag.html',
			id: 'selfTag.html',
			waiting: {
				autoShow: false
			}
		})
	} else {
		mui.openWindow({
			url: 'otherTag.html',
			id: 'otherTag.html',
			waiting: {
				autoShow: false
			}
		})
	}

}

//清除个人消息记录
function clearFriend() {
	var btnArray = ['否', '是'];
	mui.confirm('你确认要清除历史消息?', '提示', btnArray, function(e) {
		if (e.index == 1) {
			db.transaction(function(tx) {
				tx.executeSql('DELETE * FROM MessageHistory  WHERE Id=? AND Phone=? AND GuideId=?', [targetId, phone, guideId]);
			    mui.toast('清除历史消息成功')
			})
		} 
	})
}